package com.example.smartstart.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.smartstart.entity.Student;
import com.example.smartstart.mapper.StudentMapper;
import com.example.smartstart.service.IStudentService;
import com.example.smartstart.utils.Md5Util;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.List;

@Service
public class StudentServiceImpl extends ServiceImpl<StudentMapper, Student> implements IStudentService {
    @Autowired
    private StudentMapper studentMapper;

    @Override
    public Integer insert(String studentId,String password,String name){
        String md5String = Md5Util.getMD5String(password);
        Student student = new Student();
        student.setStudentId(studentId);
        student.setPassword(md5String);
        student.setName(name);
        return studentMapper.insert(student);
    }

    @Override
    public Student queryStudent(String studentId,String password){
        String md5String = Md5Util.getMD5String(password);
        return studentMapper.queryStudent(studentId,md5String);
    }

    @Override
    public Integer queryTotal(Student student) {
        return studentMapper.queryTotal(student);
    }

    @Override
    public List<Student> listByPage(Student student) {
        return studentMapper.listByPage(student);
    }

    @Override
    public Integer deleteMoreAccount(Integer[] ids){
        return studentMapper.deleteBatchIds(Arrays.stream(ids).toList());
    }

    @Override
    public Integer updateStatus(Integer id, String accountStatus) {
        return studentMapper.updateStatus(id,accountStatus);
    }

    @Override
    public Integer getUserId(String studentId) {
        return studentMapper.getUserId(studentId);
    }

    @Override
    public void updatePwd(Student student) {
        String password = student.getPassword();
        String md5String = Md5Util.getMD5String(password);
        Student newStudent = new Student();
        newStudent.setId(student.getId());
        newStudent.setPassword(md5String);
        studentMapper.updateById(newStudent);
    }
}
